package co.edu.usbcali.egrapico.vista.ambient;

import co.edu.usbcali.egrapico.vista.tools.JPanelTranferHandlerSender;

public class PanelPrecedentSender extends javax.swing.JInternalFrame implements java.io.Serializable {

    LPanePrecedentSender layeredPane;
    javax.swing.JScrollPane scroll1;
    private int restriction = 0;

    /**
     * Creates a new instance of PanelDragAndDrop
     */
    public PanelPrecedentSender() {
        super("",//+(++openFrameCount) 
                true, //resizable
                true, //closable
                true, //maximizable
                true);//iconifiable
        scroll1 = new javax.swing.JScrollPane();
        scroll1.setAutoscrolls(true);
        layeredPane = new LPanePrecedentSender();
        scroll1.setViewportView(layeredPane);
        getContentPane().add(scroll1);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setTransferHandler(new JPanelTranferHandlerSender());
        setSize(300, 300);
        //Set the window's location.
        setLocation(30, 30);
        setVisible(true);

    }

    public LPanePrecedentSender getLPane() {
        return layeredPane;
    }

    public void addMyListenerToLPane() {
        setTransferHandler(new JPanelTranferHandlerSender());
        layeredPane.addMyListener();
    }

    public void addLayeredPane(LabelRestriction label) {
        label.setNameParent(getTitle());
        if (label.getName().equals("Sender")) {
            label.setName(label.getName() + (++restriction));
            label.setText(label.getName());
            label.setTextToolTip(label.getName() + ": ");
        }
        layeredPane.addLabel(label);
        layeredPane.addLabeltoVector(label);
        try {
            setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    public void loadPresedent(PanelPrecedentSender ob) {
        layeredPane.setPreferredSize(ob.getLPane().getPreferredSize());
        layeredPane.setAreaLP(ob.getLPane().areaLPane());
        setTitle(ob.getTitle());
        for (int i = 0; i < ob.getLPane().getComponentCount(); i++) {
            LabelRestriction label = new LabelRestriction((LabelRestriction) ob.getLPane().getComponent(i));
            label.setHorizontalTextPosition(javax.swing.JLabel.CENTER);
            label.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);
            label.setName(((LabelRestriction) ob.getLPane().getComponent(i)).getName());
            label.setTextToolTip(label.getName() + ": ");
            label.setIsOfObject(true);
            label.setLocation(((LabelRestriction) ob.getLPane().getComponent(i)).getLocation());
            label.setSize(80, 80);
            label.setReception(true);
            layeredPane.addLabel(label);
            layeredPane.addLabeltoVector(label);
            label.Ladicionar();
        }
        layeredPane.ApIcons(null);
    }

    public void setUndoLPane() {
        layeredPane.Undo();
    }

    public void setRedoLPane() {
        layeredPane.Redo();
    }

    public int getRedosize() {
        return layeredPane.getRedoSize();
    }

    public int getUndosize() {
        return layeredPane.getUndoSize();
    }
}